<template>
  <default-layout>
    <header-back text="我的反馈" slot="header"></header-back>
    <mt-navbar v-model="selected" slot="header" style="margin: 0 0 3px 0;">
      <mt-tab-item :id="1">我的表扬</mt-tab-item>
      <mt-tab-item :id="2">我的投诉</mt-tab-item>
      <mt-tab-item :id="3">我的建议</mt-tab-item>
    </mt-navbar>
    <div
      v-infinite-scroll="loadMore"
      infinite-scroll-disabled="disabledScroll"
      infinite-scroll-distance="10"
      infinite-scroll-immediate-check="false"
      slot="main"
      class="scroll-view">
      <div class="list">
        <div @click="detail(item)" class="list-item" v-for="(item, key) in list" :key="key">
          <div class="send">
            <div class="top">
              <span class="desc">编号：{{item.ess002}}</span>
              <span class="desc">{{$dateFormat(item.ess010).format('YYYY-MM-DD')}}</span>
            </div>
            <div class="tit">{{item.esa201}}</div>
            <div class="con">{{item.esa202}}</div>
          </div>
          <div class="back" >
            <div class="top">
              <span>状态：<span class="pending" v-if="Number(item.esb001) === 1">未回复</span><span class="response" v-else>已回复</span></span>
              <span v-if="Number(item.esb001) === 2">回复日期：{{$dateFormat(item.esb004).format('YYYY-MM-DD')}}</span>
            </div>
            <div class="con" v-show="Number(item.esb001) === 2">回复内容：{{item.esb002}}</div>
          </div>
        </div>
      </div>
      <loading-text v-if="loading"></loading-text>
      <finish-text v-if="noMore"></finish-text>
      <empty v-if="empty"></empty>
      <yd-backtop></yd-backtop>
    </div>
    <transition name="router" mode="out-in">
      <router-view class="fixed-router"></router-view>
    </transition>
  </default-layout>
</template>
<script>
  import HeaderBack from '../../../components/header-back/header-back.vue'
  import LoadingText from '../../../components/loading-text/loading-text.vue'
  import FinishText from '../../../components/finish-text/finish-text.vue'
  import DefaultLayout from '../../../layouts/default-layout/default-layout'
  import {STORAGE_TYPE} from '../../../common/js/config'
  import Empty from '../../../components/empty/empty'
  import {infinite} from '../../../common/js/mixin'

  export default {
    components: {
      Empty,
      DefaultLayout,
      FinishText,
      LoadingText,
      HeaderBack},
    data() {
      return {
        selected: 1,
        /* 以下五个参数为上拉加载页面必需的参数 */
        loading: true,
        page: 1,
        size: 10,
        total: 0,
        list: []
        /* 以上五个参数为上拉加载页面必需的参数 */
      }
    },
    computed: {
      ...infinite
    },
    methods: {
      loadMore() {
        if (this.page === 1) this.list = []
        this.$post('/sapi/iwantsay/say/list', {
          type: this.selected,
          page: this.page,
          pageSize: this.size,
          queryType: 'self'
        }, loading => {
          this.loading = loading
        }).then(res => {
          this.list = this.list.concat(res.data.list)
          this.total = res.data.pager.totalRecord
          this.page++
        })
      },
      detail(val) {
        let titleCont = '我要表扬'
        if (this.selected === 1) {
          titleCont = '我要表扬'
        } else if (this.selected === 2) {
          titleCont = '我要投诉'
        } else {
          titleCont = '我要建议'
        }
        /*
        * title: '主任信箱',
          发送标题: val.esa201,
          发送内容: val.esa202,
          发送时间: val.aae036,
          状态: Number(val.esb001),
          回复内容: val.esb002,
          回复时间: val.esb004
        * */
        sessionStorage.setItem(STORAGE_TYPE.suggest, JSON.stringify(Object.assign({title: titleCont}, val)))
        this.$router.push({
          name: 'mySuggestDetail'
        })
      }
    },
    created() {
      this.loadMore()
      this.$watch('selected', () => {
        setTimeout(() => {
          this.page = 1
          this.loadMore()
        }, 20)
      })
    }
  }
</script>
<style lang="scss" scoped>
  @import "../../../common/style/variable";
  .scroll-view{
    padding: .15rem 0 0 0;
  }
  .list-item{
    background: #fff;
    padding: .2rem;
    display: block;
    &:not(:last-child){
      margin: 0 0 .15rem 0;
    }
    .send{
      padding: 0 0 .2rem 0;
      border-bottom: 1px solid #ededed;
      .top{
        display: flex;
        align-items: center;
        justify-content: space-between;
        color: #666;
        padding: 0 0 .1rem 0;
      }
      .tit{
        width: 100%;
        font-size: .32rem;
        color: #000;
        @include ellipsis;
      }
      .con{
        padding: .05rem 0 0 0;
        width: 100%;
        color: #333;
        @include ellipsis;
      }
    }
    .back{
      padding: .2rem 0 0 0;
      .top{
        color: #333;
        display: flex;
        align-items: center;
        justify-content: space-between;
      }
      .con{
        color: #333;
        width: 100%;
        @include ellipsis;
        padding: .1rem 0 0 0;
      }
    }
  }
  .response{
    color: $primary;
  }
  .pending{
    color: $danger;
  }
</style>
